﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace HalconDotNet
{
	/// <summary>
	///   This class manages all communication with the HALCON library
	/// </summary>
	// Token: 0x02000079 RID: 121
	[SuppressUnmanagedCodeSecurity]
	public class HalconAPI
	{
		// Token: 0x06001D10 RID: 7440 RVA: 0x000059BD File Offset: 0x00003BBD
		private HalconAPI()
		{
		}

		// Token: 0x06001D11 RID: 7441 RVA: 0x000B3B48 File Offset: 0x000B1D48
		private static bool testWindows()
		{
			int platform = (int)Environment.OSVersion.Platform;
			return platform != 4 && platform != 128;
		}

		/// <summary>
		///   Setting DoLicenseError(false) disables the license error dialog and
		///   application termination. Instead, an exception is raised.
		/// </summary>
		// Token: 0x06001D12 RID: 7442
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIDoLicenseError")]
		public static extern void DoLicenseError([MarshalAs(UnmanagedType.Bool)] bool state);

		/// <summary>
		///   Setting HLIUseSpinLock(false) before calling the first operator
		///   will cause HALCON to use mutex synchronization instead of spin locks.
		///   This is usually less efficient but may prevent problems if a large
		///   number of threads with differing priorities is used.
		/// </summary>
		// Token: 0x06001D13 RID: 7443
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIUseSpinLock")]
		public static extern void UseSpinLock([MarshalAs(UnmanagedType.Bool)] bool state);

		/// <summary>
		///   Setting HLIStartUpThreadPool(false) before calling the first
		///   operator will disable the thread pool of HALCON
		/// </summary>
		// Token: 0x06001D14 RID: 7444
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIStartUpThreadPool")]
		public static extern void StartUpThreadPool([MarshalAs(UnmanagedType.Bool)] bool state);

		/// <summary>
		///   Aborts a draw_* operator as a right-click would (Windows only)
		/// </summary>
		// Token: 0x06001D15 RID: 7445
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLICancelDraw")]
		public static extern void CancelDraw();

		/// <summary>
		///   Returns whereas HALCON character encoding is set to UTF8 or locale.
		/// </summary>
		// Token: 0x06001D16 RID: 7446
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIIsUTF8Encoding")]
		[return: MarshalAs(UnmanagedType.Bool)]
		private static extern bool IsUTF8Encoding();

		// Token: 0x06001D17 RID: 7447
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIGetSerializedSize(IntPtr ptr, out ulong size);

		// Token: 0x06001D18 RID: 7448 RVA: 0x000B3B74 File Offset: 0x000B1D74
		internal static int GetSerializedSize(byte[] header, out ulong size)
		{
			GCHandle gchandle = GCHandle.Alloc(header, GCHandleType.Pinned);
			int result = HalconAPI.HLIGetSerializedSize(gchandle.AddrOfPinnedObject(), out size);
			gchandle.Free();
			return result;
		}

		// Token: 0x06001D19 RID: 7449
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLILock")]
		internal static extern void Lock();

		// Token: 0x06001D1A RID: 7450
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIUnlock")]
		internal static extern void Unlock();

		// Token: 0x06001D1B RID: 7451
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXCreateHThreadContext(out IntPtr context);

		// Token: 0x06001D1C RID: 7452
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXClearHThreadContext(IntPtr context);

		// Token: 0x06001D1D RID: 7453
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXCreateHThread(IntPtr contextHandle, out IntPtr threadHandle);

		// Token: 0x06001D1E RID: 7454
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXClearHThread(IntPtr threadHandle);

		// Token: 0x06001D1F RID: 7455
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXExitHThread(IntPtr threadHandle);

		// Token: 0x06001D20 RID: 7456
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXStartHThreadDotNet(IntPtr threadHandle, HalconAPI.HDevThreadInternalCallback proc, IntPtr data, out IntPtr threadId);

		// Token: 0x06001D21 RID: 7457
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXPrepareDirectCall(IntPtr threadHandle);

		// Token: 0x06001D22 RID: 7458
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXJoinHThread(IntPtr threadId);

		// Token: 0x06001D23 RID: 7459
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXThreadLockLocalVar(IntPtr threadHandle, out IntPtr referenceCount);

		// Token: 0x06001D24 RID: 7460
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXThreadUnlockLocalVar(IntPtr threadHandle);

		// Token: 0x06001D25 RID: 7461
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXThreadLockGlobalVar(IntPtr threadHandle);

		// Token: 0x06001D26 RID: 7462
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HXThreadUnlockGlobalVar(IntPtr threadHandle);

		// Token: 0x06001D27 RID: 7463
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLICreateProcedure")]
		private static extern int CreateProcedure(int procIndex, out IntPtr proc);

		// Token: 0x06001D28 RID: 7464
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLICallProcedure")]
		public static extern int CallProcedure(IntPtr proc);

		// Token: 0x06001D29 RID: 7465
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIDestroyProcedure")]
		public static extern int DestroyProcedure(IntPtr proc, int procResult);

		// Token: 0x06001D2A RID: 7466
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr HLIGetLogicalName(IntPtr proc);

		// Token: 0x06001D2B RID: 7467 RVA: 0x000B3B9D File Offset: 0x000B1D9D
		internal static string GetLogicalName(IntPtr proc)
		{
			return Marshal.PtrToStringAnsi(HalconAPI.HLIGetLogicalName(proc));
		}

		// Token: 0x06001D2C RID: 7468
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLILogicalName")]
		private static extern IntPtr HLIGetLogicalName(int procIndex);

		// Token: 0x06001D2D RID: 7469 RVA: 0x000B3BAA File Offset: 0x000B1DAA
		internal static string GetLogicalName(int procIndex)
		{
			return Marshal.PtrToStringAnsi(HalconAPI.HLIGetLogicalName(procIndex));
		}

		// Token: 0x06001D2E RID: 7470
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetProcIndex")]
		private static extern int GetProcIndex(IntPtr proc);

		// Token: 0x06001D2F RID: 7471
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIGetErrorMessage(int err, IntPtr buffer);

		// Token: 0x06001D30 RID: 7472 RVA: 0x000B3BB8 File Offset: 0x000B1DB8
		internal static string GetErrorMessage(int err)
		{
			IntPtr intPtr = Marshal.AllocHGlobal(1024);
			HalconAPI.HLIGetErrorMessage(err, intPtr);
			string result = HalconAPI.FromHalconEncoding(intPtr, false);
			Marshal.FreeHGlobal(intPtr);
			return result;
		}

		// Token: 0x06001D31 RID: 7473 RVA: 0x000B3BE8 File Offset: 0x000B1DE8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static IntPtr PreCall(int procIndex)
		{
			IntPtr result;
			int num = HalconAPI.CreateProcedure(procIndex, out result);
			if (num != 2)
			{
				HOperatorException.throwInfo(num, "Could not create a new operator instance for id " + procIndex);
			}
			return result;
		}

		// Token: 0x06001D32 RID: 7474 RVA: 0x000B3C1C File Offset: 0x000B1E1C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void PostCall(IntPtr proc, int procResult)
		{
			int procIndex = HalconAPI.GetProcIndex(proc);
			HalconAPI.HLIClearAllIOCT(proc);
			int err = HalconAPI.DestroyProcedure(proc, procResult);
			if (procIndex >= 0)
			{
				HOperatorException.throwOperator(err, procIndex);
				HOperatorException.throwOperator(procResult, procIndex);
				return;
			}
			HOperatorException.throwOperator(err, "Unknown");
			HOperatorException.throwOperator(procResult, "Unknown");
		}

		// Token: 0x06001D33 RID: 7475
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetInputObject")]
		internal static extern int SetInputObject(IntPtr proc, int parIndex, IntPtr key);

		// Token: 0x06001D34 RID: 7476
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetOutputObject")]
		internal static extern int GetOutputObject(IntPtr proc, int parIndex, out IntPtr key);

		// Token: 0x06001D35 RID: 7477 RVA: 0x000B3C68 File Offset: 0x000B1E68
		internal static void ClearObject(IntPtr key)
		{
			IntPtr proc = HalconAPI.PreCall(585);
			HalconAPI.HCkP(proc, HalconAPI.SetInputObject(proc, 1, key));
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
		}

		// Token: 0x06001D36 RID: 7478
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLICopyObject(IntPtr keyIn, out IntPtr keyOut);

		// Token: 0x06001D37 RID: 7479 RVA: 0x000B3C9C File Offset: 0x000B1E9C
		internal static IntPtr CopyObject(IntPtr key)
		{
			IntPtr proc = HalconAPI.PreCall(583);
			HalconAPI.HCkP(proc, HalconAPI.SetInputObject(proc, 1, key));
			HalconAPI.StoreI(proc, 0, 1);
			HalconAPI.StoreI(proc, 1, -1);
			int num = HalconAPI.CallProcedure(proc);
			if (!HalconAPI.IsFailure(num))
			{
				num = HalconAPI.GetOutputObject(proc, 1, out key);
			}
			HalconAPI.PostCall(proc, num);
			return key;
		}

		// Token: 0x06001D38 RID: 7480 RVA: 0x000B3CF4 File Offset: 0x000B1EF4
		internal static string GetObjClass(IntPtr key)
		{
			HTuple htuple = "object";
			IntPtr proc = HalconAPI.PreCall(594);
			HalconAPI.HCkP(proc, HalconAPI.SetInputObject(proc, 1, key));
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			if (!HalconAPI.IsFailure(num))
			{
				num = HTuple.LoadNew(proc, 0, num, out htuple);
			}
			HalconAPI.PostCall(proc, num);
			if (htuple.Length <= 0)
			{
				return "any";
			}
			return htuple.S;
		}

		// Token: 0x06001D39 RID: 7481 RVA: 0x000B3D64 File Offset: 0x000B1F64
		internal static void AssertObjectClass(IntPtr key, string assertClass)
		{
			if (key != HObjectBase.UNDEF)
			{
				string objClass = HalconAPI.GetObjClass(key);
				if (!objClass.StartsWith(assertClass) && objClass != "any")
				{
					throw new HalconException(string.Concat(new string[]
					{
						"Iconic object type mismatch (expected ",
						assertClass,
						", got ",
						objClass,
						")"
					}));
				}
			}
		}

		// Token: 0x06001D3A RID: 7482
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLICreateTuple")]
		public static extern int CreateTuple(out IntPtr tuple);

		// Token: 0x06001D3B RID: 7483
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIInitOCT")]
		public static extern int InitOCT(IntPtr proc, int parIndex);

		// Token: 0x06001D3C RID: 7484
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		public static extern int HLIClearAllIOCT(IntPtr proc);

		// Token: 0x06001D3D RID: 7485
		[EditorBrowsable(EditorBrowsableState.Never)]
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIDestroyTuple")]
		public static extern int DestroyTuple(IntPtr tuple);

		// Token: 0x06001D3E RID: 7486 RVA: 0x000B3DCC File Offset: 0x000B1FCC
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreTuple(IntPtr tupleHandle, HTuple tuple)
		{
			HTupleType type = (tuple.Type == HTupleType.LONG) ? HTupleType.INTEGER : tuple.Type;
			HalconAPI.HCkH(HalconAPI.CreateElementsOfType(tupleHandle, tuple.Length, type));
			HTupleType type2 = tuple.Type;
			if (type2 <= HTupleType.MIXED)
			{
				switch (type2)
				{
				case HTupleType.INTEGER:
					HalconAPI.HCkH(HalconAPI.SetIArr(tupleHandle, tuple.IArr));
					return;
				case HTupleType.DOUBLE:
					HalconAPI.HCkH(HalconAPI.SetDArr(tupleHandle, tuple.DArr));
					return;
				case (HTupleType)3:
					break;
				case HTupleType.STRING:
				{
					string[] sarr = tuple.SArr;
					for (int i = 0; i < tuple.Length; i++)
					{
						HalconAPI.HCkH(HalconAPI.SetS(tupleHandle, i, sarr[i], true));
					}
					return;
				}
				default:
				{
					if (type2 != HTupleType.MIXED)
					{
						return;
					}
					object[] oarr = tuple.data.OArr;
					for (int j = 0; j < tuple.Length; j++)
					{
						int objectType = HTupleImplementation.GetObjectType(oarr[j]);
						switch (objectType)
						{
						case 1:
							HalconAPI.HCkH(HalconAPI.SetI(tupleHandle, j, (int)oarr[j]));
							break;
						case 2:
							HalconAPI.HCkH(HalconAPI.SetD(tupleHandle, j, (double)oarr[j]));
							break;
						case 3:
							break;
						case 4:
							HalconAPI.HCkH(HalconAPI.SetS(tupleHandle, j, (string)oarr[j], true));
							break;
						default:
							if (objectType != 16)
							{
								if (objectType == 129)
								{
									HalconAPI.HCkH(HalconAPI.SetL(tupleHandle, j, (long)oarr[j]));
								}
							}
							else
							{
								HalconAPI.HCkH(HalconAPI.SetH(tupleHandle, j, (HHandle)oarr[j]));
							}
							break;
						}
					}
					break;
				}
				}
				return;
			}
			if (type2 == HTupleType.HANDLE)
			{
				HHandle[] harr = tuple.HArr;
				for (int k = 0; k < tuple.Length; k++)
				{
					HalconAPI.HCkH(HalconAPI.SetH(tupleHandle, k, harr[k]));
				}
				return;
			}
			if (type2 != HTupleType.LONG)
			{
				return;
			}
			HalconAPI.HCkH(HalconAPI.SetLArr(tupleHandle, tuple.LArr));
		}

		// Token: 0x06001D3F RID: 7487 RVA: 0x000B3FB8 File Offset: 0x000B21B8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HTuple LoadTuple(IntPtr tupleHandle)
		{
			HTupleImplementation data;
			HTupleImplementation.LoadData(tupleHandle, HTupleType.MIXED, out data, true);
			return new HTuple(data);
		}

		// Token: 0x06001D40 RID: 7488 RVA: 0x000B3FD6 File Offset: 0x000B21D6
		private static void HCkH(int err)
		{
			if (HalconAPI.IsFailure(err))
			{
				throw new HOperatorException(err);
			}
		}

		// Token: 0x06001D41 RID: 7489
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetInputTuple")]
		internal static extern int GetInputTuple(IntPtr proc, int parIndex, out IntPtr tuple);

		// Token: 0x06001D42 RID: 7490
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLICreateElementsOfType")]
		internal static extern int CreateElementsOfType(IntPtr tuple, int length, HTupleType type);

		// Token: 0x06001D43 RID: 7491 RVA: 0x000B3FE8 File Offset: 0x000B21E8
		internal static int CreateInputTuple(IntPtr proc, int parIndex, int length, HTupleType type, out IntPtr tuple)
		{
			int inputTuple = HalconAPI.GetInputTuple(proc, parIndex, out tuple);
			if (!HalconAPI.IsFailure(inputTuple))
			{
				return HalconAPI.CreateElementsOfType(tuple, length, type);
			}
			return inputTuple;
		}

		// Token: 0x06001D44 RID: 7492
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetOutputTuple")]
		internal static extern int GetOutputTuple(IntPtr proc, int parIndex, [MarshalAs(UnmanagedType.Bool)] bool handleType, out IntPtr tuple);

		// Token: 0x06001D45 RID: 7493
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetTupleLength")]
		internal static extern int GetTupleLength(IntPtr tuple, out int length);

		// Token: 0x06001D46 RID: 7494
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetTupleTypeScanElem")]
		internal static extern int GetTupleTypeScanElem(IntPtr tuple, out int type);

		// Token: 0x06001D47 RID: 7495
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetElementType")]
		internal static extern int GetElementType(IntPtr tuple, int index, out HTupleType type);

		// Token: 0x06001D48 RID: 7496
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetI")]
		internal static extern int SetI(IntPtr tuple, int index, int intValue);

		// Token: 0x06001D49 RID: 7497
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetL")]
		internal static extern int SetL(IntPtr tuple, int index, long longValue);

		// Token: 0x06001D4A RID: 7498
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetD")]
		internal static extern int SetD(IntPtr tuple, int index, double doubleValue);

		// Token: 0x06001D4B RID: 7499
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HLISetS(IntPtr tuple, int index, IntPtr stringValue);

		// Token: 0x06001D4C RID: 7500
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetH")]
		internal static extern int SetH(IntPtr tuple, int index, IntPtr handleValue);

		// Token: 0x06001D4D RID: 7501
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLICopyHandle(IntPtr handle, out IntPtr handleCopy);

		// Token: 0x06001D4E RID: 7502 RVA: 0x000B4014 File Offset: 0x000B2214
		internal static IntPtr CopyHandle(IntPtr handle)
		{
			IntPtr result;
			HalconAPI.HCkH(HalconAPI.HLICopyHandle(handle, out result));
			return result;
		}

		// Token: 0x06001D4F RID: 7503
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIClearHandle")]
		internal static extern int ClearHandle(IntPtr handle);

		// Token: 0x06001D50 RID: 7504
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIAcquireExternalOwnership(IntPtr handle, out IntPtr handleLong);

		// Token: 0x06001D51 RID: 7505 RVA: 0x000B4030 File Offset: 0x000B2230
		internal static IntPtr AcquireExternalOwnership(IntPtr handle)
		{
			IntPtr result;
			HalconAPI.HCkH(HalconAPI.HLIAcquireExternalOwnership(handle, out result));
			return result;
		}

		// Token: 0x06001D52 RID: 7506
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIReleaseExternalOwnership")]
		internal static extern int ReleaseExternalOwnership(IntPtr handle);

		// Token: 0x06001D53 RID: 7507
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIHandleToHlong(IntPtr handle, out IntPtr handleLong);

		// Token: 0x06001D54 RID: 7508 RVA: 0x000B404C File Offset: 0x000B224C
		internal static IntPtr HandleToHlong(IntPtr handle)
		{
			IntPtr result;
			HalconAPI.HCkH(HalconAPI.HLIHandleToHlong(handle, out result));
			return result;
		}

		// Token: 0x06001D55 RID: 7509
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIHandleIsValid(IntPtr handle, [MarshalAs(UnmanagedType.Bool)] out bool is_valid);

		// Token: 0x06001D56 RID: 7510 RVA: 0x000B4068 File Offset: 0x000B2268
		internal static bool HandleIsValid(IntPtr handle)
		{
			bool result;
			HalconAPI.HCkH(HalconAPI.HLIHandleIsValid(handle, out result));
			return result;
		}

		// Token: 0x06001D57 RID: 7511
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIHGetGV_LegacyHandleMode([MarshalAs(UnmanagedType.Bool)] out bool is_valid);

		// Token: 0x06001D58 RID: 7512 RVA: 0x000B4084 File Offset: 0x000B2284
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static bool IsLegacyHandleMode()
		{
			bool result;
			HalconAPI.HCkH(HalconAPI.HLIHGetGV_LegacyHandleMode(out result));
			return result;
		}

		// Token: 0x06001D59 RID: 7513
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIGetHandleSemType(IntPtr handle, out IntPtr sem_type);

		// Token: 0x06001D5A RID: 7514 RVA: 0x000B40A0 File Offset: 0x000B22A0
		internal static string GetHandleSemType(IntPtr handle)
		{
			IntPtr halcon;
			HalconAPI.HCkH(HalconAPI.HLIGetHandleSemType(handle, out halcon));
			return HalconAPI.FromHalconEncoding(halcon, false);
		}

		// Token: 0x06001D5B RID: 7515 RVA: 0x000B40C1 File Offset: 0x000B22C1
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static IntPtr ToHalconHGlobalEncoding(string dotnet, bool force_utf8)
		{
			if (!force_utf8 && !HalconAPI.IsUTF8Encoding())
			{
				return Marshal.StringToHGlobalAnsi(dotnet);
			}
			return HalconAPI.ToHGlobalUtf8Encoding(dotnet);
		}

		// Token: 0x06001D5C RID: 7516 RVA: 0x000B40DC File Offset: 0x000B22DC
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static IntPtr ToHGlobalUtf8Encoding(string dotnet)
		{
			byte[] bytes = Encoding.UTF8.GetBytes(dotnet);
			int num = Marshal.SizeOf(bytes.GetType().GetElementType()) * bytes.Length;
			IntPtr intPtr = Marshal.AllocHGlobal(num + 1);
			Marshal.Copy(bytes, 0, intPtr, bytes.Length);
			Marshal.WriteByte(intPtr, num, 0);
			return intPtr;
		}

		// Token: 0x06001D5D RID: 7517 RVA: 0x000B4128 File Offset: 0x000B2328
		internal static int SetS(IntPtr tuple, int index, string dotnet_string, bool force_utf8)
		{
			IntPtr intPtr = HalconAPI.ToHalconHGlobalEncoding(dotnet_string, force_utf8);
			int result = HalconAPI.HLISetS(tuple, index, intPtr);
			Marshal.FreeHGlobal(intPtr);
			return result;
		}

		// Token: 0x06001D5E RID: 7518 RVA: 0x000B414C File Offset: 0x000B234C
		internal static int SetIP(IntPtr tuple, int index, IntPtr intPtrValue)
		{
			int result;
			if (HalconAPI.isPlatform64)
			{
				result = HalconAPI.SetL(tuple, index, intPtrValue.ToInt64());
			}
			else
			{
				result = HalconAPI.SetI(tuple, index, intPtrValue.ToInt32());
			}
			return result;
		}

		// Token: 0x06001D5F RID: 7519 RVA: 0x000B4184 File Offset: 0x000B2384
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreI(IntPtr proc, int parIndex, int intValue)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.INTEGER, out tuple));
			HalconAPI.SetI(tuple, 0, intValue);
		}

		// Token: 0x06001D60 RID: 7520 RVA: 0x000B41AC File Offset: 0x000B23AC
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreL(IntPtr proc, int parIndex, long longValue)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.INTEGER, out tuple));
			HalconAPI.SetL(tuple, 0, longValue);
		}

		// Token: 0x06001D61 RID: 7521 RVA: 0x000B41D4 File Offset: 0x000B23D4
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreD(IntPtr proc, int parIndex, double doubleValue)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.DOUBLE, out tuple));
			HalconAPI.SetD(tuple, 0, doubleValue);
		}

		// Token: 0x06001D62 RID: 7522 RVA: 0x000B41FC File Offset: 0x000B23FC
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreS(IntPtr proc, int parIndex, string stringValue)
		{
			if (stringValue == null)
			{
				stringValue = "";
			}
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.STRING, out tuple));
			HalconAPI.HCkP(proc, HalconAPI.SetS(tuple, 0, stringValue, false));
		}

		// Token: 0x06001D63 RID: 7523 RVA: 0x000B4234 File Offset: 0x000B2434
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreH(IntPtr proc, int parIndex, IntPtr handleValue)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.HANDLE, out tuple));
			HalconAPI.HCkP(proc, HalconAPI.SetH(tuple, 0, handleValue));
		}

		// Token: 0x06001D64 RID: 7524 RVA: 0x000B4264 File Offset: 0x000B2464
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void StoreIP(IntPtr proc, int parIndex, IntPtr intPtrValue)
		{
			IntPtr tuple;
			HalconAPI.HCkP(proc, HalconAPI.CreateInputTuple(proc, parIndex, 1, HTupleType.INTEGER, out tuple));
			HalconAPI.SetIP(tuple, 0, intPtrValue);
		}

		// Token: 0x06001D65 RID: 7525 RVA: 0x000B428B File Offset: 0x000B248B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void Store(IntPtr proc, int parIndex, HTuple tupleValue)
		{
			if (tupleValue == null)
			{
				tupleValue = new HTuple();
			}
			tupleValue.Store(proc, parIndex);
		}

		// Token: 0x06001D66 RID: 7526 RVA: 0x000B429F File Offset: 0x000B249F
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void Store(IntPtr proc, int parIndex, HHandle handleValue)
		{
			if (handleValue == null)
			{
				handleValue = new HHandle();
			}
			handleValue.Store(proc, parIndex);
		}

		// Token: 0x06001D67 RID: 7527 RVA: 0x000B42B3 File Offset: 0x000B24B3
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void Store(IntPtr proc, int parIndex, HObjectBase objectValue)
		{
			if (objectValue == null)
			{
				objectValue = new HObjectBase();
			}
			objectValue.Store(proc, parIndex);
		}

		// Token: 0x06001D68 RID: 7528
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetIArr")]
		internal static extern int SetIArr(IntPtr tuple, int[] intArray);

		// Token: 0x06001D69 RID: 7529
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetIArrPtr")]
		internal static extern int SetIArrPtr(IntPtr tuple, int[] intArray, int length);

		// Token: 0x06001D6A RID: 7530
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetLArr")]
		internal static extern int SetLArr(IntPtr tuple, long[] longArray);

		// Token: 0x06001D6B RID: 7531
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetLArrPtr")]
		internal static extern int SetLArrPtr(IntPtr tuple, long[] longArray, int length);

		// Token: 0x06001D6C RID: 7532
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetDArr")]
		internal static extern int SetDArr(IntPtr tuple, double[] doubleArray);

		// Token: 0x06001D6D RID: 7533
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLISetDArrPtr")]
		internal static extern int SetDArrPtr(IntPtr tuple, double[] doubleArray, int length);

		// Token: 0x06001D6E RID: 7534
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetI")]
		internal static extern int GetI(IntPtr tuple, int index, out int intValue);

		// Token: 0x06001D6F RID: 7535
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetL")]
		internal static extern int GetL(IntPtr tuple, int index, out long longValue);

		// Token: 0x06001D70 RID: 7536
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HLIGetH(IntPtr tuple, int index, out IntPtr longValue);

		// Token: 0x06001D71 RID: 7537
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetD")]
		internal static extern int GetD(IntPtr tuple, int index, out double doubleValue);

		// Token: 0x06001D72 RID: 7538
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		private static extern int HLIGetS(IntPtr tuple, int index, out IntPtr stringPtr);

		// Token: 0x06001D73 RID: 7539 RVA: 0x000B42C8 File Offset: 0x000B24C8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static string FromHalconEncoding(IntPtr halcon, bool force_utf8)
		{
			if (force_utf8 || HalconAPI.IsUTF8Encoding())
			{
				int num = 0;
				while (Marshal.ReadByte(halcon, num) != 0)
				{
					num++;
				}
				byte[] array = new byte[num];
				Marshal.Copy(halcon, array, 0, array.Length);
				return Encoding.UTF8.GetString(array);
			}
			return Marshal.PtrToStringAnsi(halcon);
		}

		// Token: 0x06001D74 RID: 7540 RVA: 0x000B4318 File Offset: 0x000B2518
		internal static int GetS(IntPtr tuple, int index, out string stringValue, bool force_utf8)
		{
			stringValue = string.Empty;
			IntPtr halcon;
			int num = HalconAPI.HLIGetS(tuple, index, out halcon);
			if (num != 2)
			{
				return num;
			}
			stringValue = HalconAPI.FromHalconEncoding(halcon, force_utf8);
			if (stringValue == null)
			{
				stringValue = "";
				return 5;
			}
			return 2;
		}

		// Token: 0x06001D75 RID: 7541 RVA: 0x000B4354 File Offset: 0x000B2554
		internal static int GetH(IntPtr tuple, int index, out HHandle handle)
		{
			IntPtr handle2;
			int result = HalconAPI.HLIGetH(tuple, index, out handle2);
			handle = new HHandle(handle2);
			return result;
		}

		// Token: 0x06001D76 RID: 7542 RVA: 0x000B4374 File Offset: 0x000B2574
		internal static int GetIP(IntPtr tuple, int index, out IntPtr intPtrValue)
		{
			int result;
			if (HalconAPI.isPlatform64)
			{
				long value;
				result = HalconAPI.GetL(tuple, index, out value);
				intPtrValue = new IntPtr(value);
			}
			else
			{
				int value2;
				result = HalconAPI.GetI(tuple, index, out value2);
				intPtrValue = new IntPtr(value2);
			}
			return result;
		}

		// Token: 0x06001D77 RID: 7543 RVA: 0x000B43B0 File Offset: 0x000B25B0
		private static int HCkSingle(IntPtr tuple, HTupleType expectedType)
		{
			int num = 0;
			if (tuple != IntPtr.Zero)
			{
				HalconAPI.GetTupleLength(tuple, out num);
			}
			if (num <= 0)
			{
				return 7001;
			}
			HTupleType htupleType;
			HalconAPI.GetElementType(tuple, 0, out htupleType);
			if (htupleType != expectedType)
			{
				return 7002;
			}
			return 2;
		}

		// Token: 0x06001D78 RID: 7544 RVA: 0x000B43F4 File Offset: 0x000B25F4
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadI(IntPtr proc, int parIndex, int err, out int intValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				intValue = -1;
				return err;
			}
			IntPtr zero = IntPtr.Zero;
			HalconAPI.GetOutputTuple(proc, parIndex, false, out zero);
			err = HalconAPI.HCkSingle(zero, HTupleType.INTEGER);
			if (err == 2)
			{
				return HalconAPI.GetI(zero, 0, out intValue);
			}
			err = HalconAPI.HCkSingle(zero, HTupleType.DOUBLE);
			if (err != 2)
			{
				intValue = -1;
				return err;
			}
			double num = -1.0;
			err = HalconAPI.GetD(zero, 0, out num);
			intValue = (int)num;
			return err;
		}

		// Token: 0x06001D79 RID: 7545 RVA: 0x000B4464 File Offset: 0x000B2664
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadL(IntPtr proc, int parIndex, int err, out long longValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				longValue = -1L;
				return err;
			}
			IntPtr zero = IntPtr.Zero;
			HalconAPI.GetOutputTuple(proc, parIndex, false, out zero);
			err = HalconAPI.HCkSingle(zero, HTupleType.INTEGER);
			if (err == 2)
			{
				return HalconAPI.GetL(zero, 0, out longValue);
			}
			err = HalconAPI.HCkSingle(zero, HTupleType.DOUBLE);
			if (err != 2)
			{
				longValue = -1L;
				return err;
			}
			double num = -1.0;
			err = HalconAPI.GetD(zero, 0, out num);
			longValue = (long)num;
			return err;
		}

		// Token: 0x06001D7A RID: 7546 RVA: 0x000B44D4 File Offset: 0x000B26D4
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadD(IntPtr proc, int parIndex, int err, out double doubleValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				doubleValue = -1.0;
				return err;
			}
			IntPtr zero = IntPtr.Zero;
			HalconAPI.GetOutputTuple(proc, parIndex, false, out zero);
			err = HalconAPI.HCkSingle(zero, HTupleType.DOUBLE);
			if (err == 2)
			{
				return HalconAPI.GetD(zero, 0, out doubleValue);
			}
			err = HalconAPI.HCkSingle(zero, HTupleType.INTEGER);
			if (err != 2)
			{
				doubleValue = -1.0;
				return err;
			}
			int num = -1;
			err = HalconAPI.GetI(zero, 0, out num);
			doubleValue = (double)num;
			return err;
		}

		// Token: 0x06001D7B RID: 7547 RVA: 0x000B454C File Offset: 0x000B274C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadS(IntPtr proc, int parIndex, int err, out string stringValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				stringValue = "";
				return err;
			}
			IntPtr zero = IntPtr.Zero;
			HalconAPI.GetOutputTuple(proc, parIndex, false, out zero);
			err = HalconAPI.HCkSingle(zero, HTupleType.STRING);
			if (err != 2)
			{
				stringValue = "";
				return err;
			}
			return HalconAPI.GetS(zero, 0, out stringValue, false);
		}

		// Token: 0x06001D7C RID: 7548 RVA: 0x000B459C File Offset: 0x000B279C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadIP(IntPtr proc, int parIndex, int err, out IntPtr intPtrValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				intPtrValue = IntPtr.Zero;
				return err;
			}
			IntPtr tuple;
			HalconAPI.GetOutputTuple(proc, parIndex, false, out tuple);
			err = HalconAPI.HCkSingle(tuple, HTupleType.INTEGER);
			if (err != 2)
			{
				intPtrValue = IntPtr.Zero;
				return err;
			}
			return HalconAPI.GetIP(tuple, 0, out intPtrValue);
		}

		// Token: 0x06001D7D RID: 7549 RVA: 0x000B45E4 File Offset: 0x000B27E4
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static int LoadH(IntPtr proc, int parIndex, int err, out HHandle handleValue)
		{
			if (HalconAPI.IsFailure(err))
			{
				handleValue = new HHandle();
				return err;
			}
			IntPtr tuple;
			HalconAPI.GetOutputTuple(proc, parIndex, true, out tuple);
			err = HalconAPI.HCkSingle(tuple, HTupleType.HANDLE);
			if (err != 2)
			{
				handleValue = new HHandle();
				return err;
			}
			return HalconAPI.GetH(tuple, 0, out handleValue);
		}

		// Token: 0x06001D7E RID: 7550
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetIArr")]
		internal static extern int GetIArr(IntPtr tuple, [Out] int[] intArray);

		// Token: 0x06001D7F RID: 7551
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetLArr")]
		internal static extern int GetLArr(IntPtr tuple, [Out] long[] longArray);

		// Token: 0x06001D80 RID: 7552
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl, EntryPoint = "HLIGetDArr")]
		internal static extern int GetDArr(IntPtr tuple, [Out] double[] doubleArray);

		/// <summary>
		/// Unpin the tuple's data, but first check if tuple is null. Notice that
		/// PinTuple happens in HTuple as side effect of store.
		/// </summary>
		// Token: 0x06001D81 RID: 7553 RVA: 0x000B462C File Offset: 0x000B282C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public static void UnpinTuple(HTuple tuple)
		{
			if (tuple != null)
			{
				tuple.UnpinTuple();
			}
		}

		// Token: 0x06001D82 RID: 7554
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackPush(IntPtr win_handle);

		// Token: 0x06001D83 RID: 7555
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackPop();

		// Token: 0x06001D84 RID: 7556
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackGetActive(out IntPtr win_handle);

		// Token: 0x06001D85 RID: 7557
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackSetActive(IntPtr win_handle);

		// Token: 0x06001D86 RID: 7558
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackIsOpen([MarshalAs(UnmanagedType.Bool)] out bool is_open);

		// Token: 0x06001D87 RID: 7559
		[DllImport("halcon", CallingConvention = CallingConvention.Cdecl)]
		internal static extern int HWindowStackCloseAll();

		// Token: 0x06001D88 RID: 7560 RVA: 0x000B4637 File Offset: 0x000B2837
		internal static bool IsError(int err)
		{
			return err >= 1000;
		}

		// Token: 0x06001D89 RID: 7561 RVA: 0x000B4644 File Offset: 0x000B2844
		internal static bool IsFailure(int err)
		{
			return err != 2 && err != 2;
		}

		// Token: 0x06001D8A RID: 7562 RVA: 0x000B4653 File Offset: 0x000B2853
		internal static void HCkP(IntPtr proc, int err)
		{
			if (HalconAPI.IsFailure(err))
			{
				HalconAPI.PostCall(proc, err);
			}
		}

		// Token: 0x04001139 RID: 4409
		private const string HalconDLL = "halcon";

		// Token: 0x0400113A RID: 4410
		private const CallingConvention HalconCall = CallingConvention.Cdecl;

		/// <summary>True when running on a 64-bit platform.</summary>
		// Token: 0x0400113B RID: 4411
		public static readonly bool isPlatform64 = IntPtr.Size > 4;

		/// <summary>True when running on a Windows platform.</summary>
		// Token: 0x0400113C RID: 4412
		public static readonly bool isWindows = HalconAPI.testWindows();

		// Token: 0x0400113D RID: 4413
		internal const int H_MSG_OK = 2;

		// Token: 0x0400113E RID: 4414
		internal const int H_MSG_TRUE = 2;

		// Token: 0x0400113F RID: 4415
		internal const int H_MSG_FALSE = 3;

		// Token: 0x04001140 RID: 4416
		internal const int H_MSG_VOID = 4;

		// Token: 0x04001141 RID: 4417
		internal const int H_MSG_FAIL = 5;

		// Token: 0x020000B3 RID: 179
		// (Invoke) Token: 0x0600205F RID: 8287
		public delegate int HFramegrabberCallback(IntPtr handle, IntPtr userContext, IntPtr context);

		// Token: 0x020000B4 RID: 180
		// (Invoke) Token: 0x06002063 RID: 8291
		public delegate void HProgressBarCallback(IntPtr id, string operatorName, double progress, string message);

		// Token: 0x020000B5 RID: 181
		// (Invoke) Token: 0x06002067 RID: 8295
		public delegate void HLowLevelErrorCallback(string err);

		// Token: 0x020000B6 RID: 182
		// (Invoke) Token: 0x0600206B RID: 8299
		public delegate void HClearProcCallBack(IntPtr ptr);

		// Token: 0x020000B7 RID: 183
		// (Invoke) Token: 0x0600206F RID: 8303
		[EditorBrowsable(EditorBrowsableState.Never)]
		public delegate IntPtr HDevThreadInternalCallback(IntPtr devThread);
	}
}
